package com.one.dto;

import com.one.enums.ErrorEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

//统一返回结果的类
@Data
public class Result<T> {

    @ApiModelProperty(value = "返回码")
    private String code;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private T data ;

    //把构造方法私有
    private Result() {}

    //成功静态方法
    public static Result ok() {
        Result result = new Result();
        result.setCode(ErrorEnum.SUCCESS.getResultCode());
        result.setMessage(ErrorEnum.SUCCESS.getResultMsg());
        return result;
    }

    //失败静态方法
    public static Result error() {
        Result result = new Result();
        result.setCode(ErrorEnum.NULL_DATA.getResultCode());
        result.setMessage(ErrorEnum.NULL_DATA.getResultMsg());
        return result;
    }


    public Result message(String message){
        this.setMessage(message);
        return this;
    }

    public Result code(String code){
        this.setCode(code);
        return this;
    }

    public Result data(T value){
        this.data = value;
        return this;
    }
}
